public class Parser {

	int errorNo;
	int potNo;
	Order order;
	
	public Protocall.Method parseHeader(String request, int noOfPots) {
		// if (clientInput.matches(validBREW)) {

		if (request.matches(".*\\/pot-\\d.*")) {
			potNo = Integer.parseInt(request.replaceAll("[\\D]", "")
					.substring(0, 1));
			if ((potNo < 0) && (potNo > noOfPots)) {
				errorNo = 404;
				return Protocall.Method.ERROR;
			}
		} else {
			potNo = 0;
		}

		if (request.contains("BREW")||request.contains("POST")) {
			order = new Order();
			return Protocall.Method.BREW;
		} else if (request.contains("GET")) {
			return Protocall.Method.GET;
		} else if (request.contains("PROPFIND")) {
			return Protocall.Method.PROPFIND;
		} else if (request.contains("WHEN")) {
			return Protocall.Method.WHEN;
		} else {
			errorNo = 406;
			return Protocall.Method.ERROR;
		}

		// } else {
		// errorNo = 406;
		// return Protocall.Method.ERROR;
		// }
	}

	public Order getOrder() {

		return order;
	}

	public void addToOrder(String request) {
		// Parse milk additions
		if (request.contains("Cream")) {
			order.wantsMilk(true);
			order.setMilkName("Cream");
		} else if (request.contains("Half and half")) {
			order.wantsMilk(true);
			order.setMilkName("Half and half");
		} else if (request.contains("Whole-milk")) {
			order.wantsMilk(true);
			order.setMilkName("Whole-milk");
		}
		if (request.contains("Vanilla")) {// Parse syrup
												// additions
			order.wantsSyrup(true);
			order.setSyrupName("Vanilla");
		} else if (request.contains("Almond")) {
			order.wantsSyrup(true);
			order.setSyrupName("Almond");
		} else if (request.contains("Raspberry")) {
			order.wantsSyrup(true);
			order.setSyrupName("Raspberry");
		}
		if (request.contains("Whiskey")) {// Parse alcohol
												// additions
			order.wantsSyrup(true);
			order.setAlcoholName("Whiskey");
		} else if (request.contains("Rum")) {
			order.wantsSyrup(true);
			order.setAlcoholName("Rum");
		} else if (request.contains("Kahlua")) {
			order.wantsSyrup(true);
			order.setAlcoholName("Kahlua");
		} else if (request.contains("Aquavit")) {
			order.wantsSyrup(true);
			order.setAlcoholName("Aquavit");
		}

	}

	public int getPotNo() {

		return potNo;
	}

	public int getErrorNo() {

		return errorNo;
	}
}
